package org.liuyunfeng.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: TanJingyu
 * @create: 2022-01-10 15:31
 **/
@RestController
@RequestMapping("/completable")
public class CompletableFutureController {

    @GetMapping
    public String test() {
        CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
                System.out.println("completableFuture");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).thenRun(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("哈哈");
        }).thenRunAsync(() -> System.out.println("哟一个"));

        CompletableFuture.runAsync(() -> System.out.println(""), Executors.newFixedThreadPool(1));

        return "success.";
    }
}

    